/*
 * @lc app=leetcode.cn id=706 lang=typescript
 *
 * [706] 设计哈希映射
 */

// @lc code=start
class MyHashMap {
    constructor() {}
    cache: number[][] = [];
    put(key: number, value: number): void {
        const index = this.findIndex(key);
        if (index === -1) {
            this.cache.push([key, value]);
        } else {
            this.cache[index][1] = value;
        }
    }
    private findIndex(key: number) {
        return this.cache.findIndex(([key1]) => {
            if (key === key1) return true;
        });
    }
    get(key: number): number {
        const index = this.findIndex(key);
        if (index === -1) {
            return -1;
        } else {
            return this.cache[index][1];
        }
    }

    remove(key: number): void {
        const index = this.findIndex(key);
        if (index !== -1) {
            this.cache.splice(index, 1);
        }
    }
}

/**
 * Your MyHashMap object will be instantiated and called as such:
 * var obj = new MyHashMap()
 * obj.put(key,value)
 * var param_2 = obj.get(key)
 * obj.remove(key)
 */
// @lc code=end
